package com.ambulance.project.biz.controller.treatter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.domain.AjaxResultData;
import com.ambulance.project.biz.entity.GCSAnswer;
import com.ambulance.project.biz.entity.Gcs;
import com.ambulance.project.biz.entity.Nhiss;
import com.ambulance.project.biz.entity.NhissAnswer;
import com.ambulance.project.biz.service.GCSAnswerService;
import com.ambulance.project.biz.service.GcsService;
import com.ambulance.project.biz.service.NhissAnswerService;
import com.ambulance.project.biz.service.NhissService;
import com.ambulance.utils.ChildUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author RXL
 * @Date 2020/5/25 11:06
 * @Version 1.0
 */
@Api(tags = {"会诊子系统终端-NHISS、GCS相关接口"})
@RestController
@RequestMapping(value = "/treat/grade/v1", method = RequestMethod.POST)
public class TreatNhissGcs {
    @Autowired
    private NhissService nhissService;
    @Autowired
    private NhissAnswerService nhissAnswerService;
    @Autowired
    private GCSAnswerService gcsAnswerService;
    @Autowired
    private GcsService gcsService;

    @ApiOperation(value = "获取NHISS答案", notes = "获取NHISS答案", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dcid", value = "病历id", required = true, paramType = "form", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    @RequestMapping(value = "/getNhissAnswer")
    @ResponseBody
    public Object getNhissAnswer(@RequestParam(value = "dcid") Integer dcid) {
        final QueryWrapper<NhissAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dcid", dcid);
        final NhissAnswer one = nhissAnswerService.getOne(queryWrapper);
        final JSONObject object = JSON.parseObject(one.getContent());
        final List<Nhiss> list = ChildUtils.getNhissChild(nhissService.list());
        for (Nhiss nhiss : list) {
            nhiss.setAnswer(object.getInteger(String.valueOf(nhiss.getNumber())));
        }
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "获取GCS答案", notes = "获取GCS答案", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dcid", value = "病历id", required = true, paramType = "form", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    @RequestMapping(value = "/getGCSAnswer")
    @ResponseBody
    public Object getGCSAnswer(@RequestParam(value = "dcid") Integer dcid) {
        final QueryWrapper<GCSAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dcid", dcid);
        final GCSAnswer one = gcsAnswerService.getOne(queryWrapper);
        final JSONObject object = JSON.parseObject(one.getContent());
        final List<Gcs> gcsList = ChildUtils.getGCSChild(gcsService.list());
        for (Gcs gcs : gcsList) {
            gcs.setAnswer(object.getInteger(String.valueOf(gcs.getNumber())));
        }
        return AjaxResult.success(gcsList);
    }

}
